package com.spring.boot.springBoot.jdbcTemple;

import com.spring.boot.springBoot.entity.UserDemo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

/**
 * Created by pactera on 2017/9/27.
 */
@Repository
public class UserDemoDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;


    /**
     * 通过id获取demo对象.
     * @param id
     * @return
     */
    public UserDemo getById(long id){
        String sql = "select * from user_demo where id=?";
        RowMapper<UserDemo> rowMapper = new BeanPropertyRowMapper<>(UserDemo.class);
        return jdbcTemplate.queryForObject(sql, rowMapper,id);
    }
}
